package com.suray.wcs.web.system.controller.monitor;

import com.suray.commin.annotation.Log;
import com.suray.commin.core.controller.BaseController;
import com.suray.commin.core.controller.ResponseData;
import com.suray.commin.core.page.TableDataInfo;
import com.suray.commin.core.utils.ExcelUtil;
import com.suray.commin.enmus.BusinessType;
import com.suray.wcs.service.system.entity.OperationLogDB;
import com.suray.wcs.service.system.service.IOperationLogDBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 操作日志记录
 *
 * @author shaozn
 */
@RestController
@RequestMapping("/monitor/operlog")
public class SysOperlogController extends BaseController {
    @Autowired
    private IOperationLogDBService IOperationLogDBService;

    @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
    @GetMapping("/list")
    public TableDataInfo list(OperationLogDB operLog) {
        startPage();
        List<OperationLogDB> list = IOperationLogDBService.selectOperLogList(operLog);
        return getDataTable(list);
    }

    @Log(title = "操作日志", method = "导出操作日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:export')")
    @GetMapping("/export")
    public ResponseData export(OperationLogDB operLog) {
        List<OperationLogDB> list = IOperationLogDBService.selectOperLogList(operLog);
        ExcelUtil<OperationLogDB> util = new ExcelUtil<OperationLogDB>(OperationLogDB.class);
        return util.exportExcel(list, "操作日志");
    }

    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @Log(title = "操作日志", method = "删除操作日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{operIds}")
    public ResponseData remove(@PathVariable Long[] operIds) {
        return toAjax(IOperationLogDBService.deleteOperLogByIds(operIds));
    }

    @Log(title = "操作日志", method = "清空操作日志", businessType = BusinessType.CLEAN)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/clean")
    public ResponseData clean() {
        IOperationLogDBService.cleanOperLog();
        return ResponseData.success();
    }
}
